import Vue from 'vue'
import Vuex from 'vuex'

import {getOperationalData, passList} from '@src/api/ImApi.js';


Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    operationalData: {}, // 新建工单，新建事件权限以及模板列表
    operationalDataByPass:[], // 新建pass模板列表
  },
  mutations: {
    set_operationalData(state, payload) {
      state.operationalData = payload
    },
    set_operationalDataByPass(state, payload){
      state.operationalDataByPass = payload
    },
  },
  actions: {
    get_operationalData(context, data) {
      return new Promise(async (resolve, reject) => {
        const { status, data } = await getOperationalData()
        if (status === 0) {
          context.commit('set_operationalData', data)
          resolve()
        }
      })
    },

    get_operationalDataByPass(context){
      return new Promise(async (resolve, reject) => {
        const { code, data } = await passList()
        if (code === 0) {
          let list = []
          data?.forEach(item => {
            if (item.menuList) {
              list = list.concat(item.menuList)
            }
          })
          context.commit('set_operationalDataByPass', list)
          resolve()
        }
      })
    }
  }
})

export default store